﻿@namespace iPanel.Components
@using iPanel.Model
@using Microsoft.FluentUI.AspNetCore.Components

@if (ViewportInformation.IsDesktop)
{
    // Either display commands or a spacer.
    // Spacer keeps a consistent placing of following buttons if there are less highlighted commands for this resource.
    @for (var i = 0; i < MaxHighlightedCount; i++)
    {
        if (i < _highlightedCommands.Count)
        {
            var highlightedCommand = _highlightedCommands[i];

            <FluentButton Appearance="Appearance.Lightweight" Title="@(!string.IsNullOrEmpty(highlightedCommand.DisplayDescription) ? highlightedCommand.DisplayDescription : highlightedCommand.DisplayName)" OnClick="@(() => CommandSelected.InvokeAsync(highlightedCommand))" Disabled="@(highlightedCommand.State == CommandViewModelState.Disabled || IsCommandExecuting(Resource, highlightedCommand))">
                @if (!string.IsNullOrEmpty(highlightedCommand.IconName) && IconResolver.ResolveIconName(highlightedCommand.IconName, IconSize.Size16, highlightedCommand.IconVariant) is { } icon)
                {
                    <FluentIcon Value="@icon" Width="16px" />
                }
                else
                {
                    @highlightedCommand.DisplayName
                }
            </FluentButton>
        }
        else
        {
            <div style="display:inline-block; width:32px;"></div>
        }
    }

    <FluentButton Appearance="Appearance.Lightweight" Title="@Loc[nameof(Resources.Resources.ResourceActionConsoleLogsText)]" OnClick="@(() => NavigationManager.NavigateTo(iPanel.Utils.DashboardUrls.ConsoleLogsUrl(resource: Resource.Name)))">
        <FluentIcon Value="@s_consoleLogsIcon" />
    </FluentButton>

    <FluentDivider Class="action-divider" Role="DividerRole.Presentation" Orientation="Orientation.Vertical" />
}

<AspireMenuButton ButtonAppearance="Appearance.Lightweight"
                  Icon="@(new Icons.Regular.Size20.MoreHorizontal())"
                  Items="@_menuItems"
                  @ref="_menuButton"
                  Title="@ControlLoc[nameof(Resources.ControlsStrings.ActionsButtonText)]" />
